home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1073 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  79 lines

  1. Path: newshost.cin.gov.au!usenet
  2. From: rossw@cin.gov.au (Ross Wilson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: array of pointers to a tree structure ?  ( right post, the other one has a miss * )
  5. Date: Thu, 11 Jan 1996 06:49:57 GMT
  6. Organization: Community Information Network
  7. Message-ID: <4d28c7$gc7@canb.cin.gov.au>
  8. References: <4d06ge$9lc@hermes.fundp.ac.be>
  9. NNTP-Posting-Host: chico.cin.gov.au
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Francisco Melo Ledermann <fmelo@biq.fundp.ac.be> wrote:
  13.  
  14. <snip>
  15. >/* BOXES STRUCTURE FOR THE CONSTRUCTION OF A TREE */
  16.  
  17. >struct boxes {
  18. >              int number;
  19. >              struct boxes *pointer_1;
  20. >              struct boxes *pointer_2;
  21. >              struct boxes *pointer_3;
  22. >             }
  23.  
  24. >struct boxes *array_pointers [15];
  25.  
  26.  
  27. <snip>
  28. > I have tried statements like this with out 
  29. >success:
  30.  
  31.  
  32. >(*(array_pointers + 1)).pointer_1 = (array_pointers + 0);
  33.  
  34. >or
  35.  
  36. >(array_pointers[1]).pointer_1 = &array_pointers[0];
  37. >                                 
  38.  
  39. >Somebody know how can I define a pointer inside the box in the way that 
  40. >it points to a box in the array ???
  41.  
  42. Francisco,
  43.  
  44. the main problem appears to be a misunderstanding about
  45. array_pointers[] and what it contains.  array_pointers[] is an array
  46. of POINTERS TO TYPE STRUCT BOXES, so array_pointers[1] is a pointer to
  47. type struct boxes.  So you can't do this:
  48.  
  49.     (array_pointers[1]).pointer_1 = &array_pointers[0];
  50.  
  51. since array_pointers[1] is a pointer, not a "struct boxes" object and
  52. &array_pointers[0] is the address of the pointer to the 0th struct
  53. boxes, not the struct itself.  There are similar problems with the
  54. other attempt above.
  55.  
  56. Try this instead:
  57.  
  58.     array_pointers[1]->pointer_1 = array_pointers[0];
  59.  
  60. Since array_pointer[1] is a pointer to an object of type struct boxes,
  61. this sets the pointer_1 element of the 1th struct to the address of
  62. the 0th struct.
  63.  
  64. Use the A->B form if A is a pointer to something containing B.  Use
  65. the A.B form where A is the actual something containing B.
  66.  
  67. I am not sure if you just left it out for the posting, but:
  68.  
  69. struct boxes
  70. {
  71. };
  72.  
  73. needs the semicolon.
  74.  
  75.  
  76. Good luck,
  77. Ross
  78.  
  79.